<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片懒加载</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        div {
            width: 375px;
        }
        img {
            width: 100%;
        }
    </style>
</head>
<body>
    <div>
        <img src="./imgs/02_imglayzyload/default.jpeg" data-src="./imgs/02_imglayzyload/1.jpeg" alt="">
        <img src="./imgs/02_imglayzyload/default.jpeg" data-src="./imgs/02_imglayzyload/2.jpeg" alt="">
        <img src="./imgs/02_imglayzyload/default.jpeg" data-src="./imgs/02_imglayzyload/3.jpeg" alt="">
        <img src="./imgs/02_imglayzyload/default.jpeg" data-src="./imgs/02_imglayzyload/4.jpeg" alt="">
        <img src="./imgs/02_imglayzyload/default.jpeg" data-src="./imgs/02_imglayzyload/5.jpeg" alt="">
        <img src="./imgs/02_imglayzyload/default.jpeg" data-src="./imgs/02_imglayzyload/6.jpeg" alt="">
        <img src="./imgs/02_imglayzyload/default.jpeg" data-src="./imgs/02_imglayzyload/7.jpeg" alt="">
        <img src="./imgs/02_imglayzyload/default.jpeg" data-src="./imgs/02_imglayzyload/8.jpeg" alt="">
    </div>
    
    <script type="module">
        // import { imgLazyload } from "./js/02_ImgLazyload/imgLazyload.js";

        // 手写图片懒加载第2遍
        // import { imgLazyload } from "./js/02_ImgLazyload/imgLazyload1.js";

        // 手写图片懒加载第3遍
        // import { imgLazyload } from "./js/02_ImgLazyload/imgLazyload2.js";

        // 图片懒加载第3遍
        import { imgLazyload } from "./js/02_ImgLazyload/imgLazyload3.js";
        window.onload = () => {
            imgLazyload(0)
            window.onscroll = () => {
                let scrollTop = document.documentElement.scrollTop ||  document.body.scrollTop
                imgLazyload(scrollTop)
            }
        }
    </script>
</body>
</html>